package cn.com.ejiakanghu.service;

import com.github.pagehelper.PageHelper;
import org.apache.ibatis.annotations.Param;
import org.linlinjava.litemall.db.dao.AgedmallPromoteWithdrawalRecordMapper;
import org.linlinjava.litemall.db.dao.divided.AgedmallInfoPromoteUserSettlementMapper;
import org.linlinjava.litemall.db.domain.AgedmallPromoteWithdrawalRecord;
import org.linlinjava.litemall.db.domain.AgedmallPromoteWithdrawalRecordExample;
import org.linlinjava.litemall.db.domain.AgedmallUserCashout;
import org.linlinjava.litemall.db.domain.AgedmallUserCashoutExample;
import org.linlinjava.litemall.db.vo.app.ProxyMoneyVo;
import org.linlinjava.litemall.db.vo.app.SettleStatisticsVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author huangfei
 * @create 2021-12-29 10:25
 */
@Service
@Transactional
public class AgedmallInfoPromoteUserSettlementService {

    @Resource
    private AgedmallInfoPromoteUserSettlementMapper infoPromoteUserSettlementMapper;

    @Resource
    private AgedmallPromoteWithdrawalRecordMapper agedmallPromoteWithdrawalRecordMapper;

    /**
     * 分成统计
     * @param userId
     * @param year
     * @return
     */
    public List<SettleStatisticsVo> getSettleStatisticsVo(Integer userId, Integer year) {
        return infoPromoteUserSettlementMapper.getSettleStatisticsVo(userId, year);
    }


    public BigDecimal getSettleByYearMonth(Integer userId, Integer year, Integer month) {
        return infoPromoteUserSettlementMapper.getSettleByYearMonth(userId, year, month);
    }


    public List<ProxyMoneyVo> getProxyMoneyVoList(Integer userId, Integer year, Integer month, Byte item) {
        return infoPromoteUserSettlementMapper.getProxyMoneyVoList(userId, year, month, item);
    }

    /**
     * 统计某个月分成总金额
     * @param userId
     * @param year
     * @param month
     * @return
     */
    public BigDecimal getProxyMoneyMontyProxy(@Param("userId") Integer userId, @Param("year") Integer year, @Param("month") Integer month){
        return infoPromoteUserSettlementMapper.getProxyMoneyMontyProxy(userId,year,month);
    }


    /**
     * 根据用户id查询明细信息
     * @param userId
     * @param page
     * @param limit
     * @return
     */
    public List<AgedmallPromoteWithdrawalRecord> list(Integer userId, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        AgedmallPromoteWithdrawalRecordExample example = new AgedmallPromoteWithdrawalRecordExample();
        example.or().andUserIdEqualTo(userId);
        example.setOrderByClause("respTime DESC");
        return agedmallPromoteWithdrawalRecordMapper.selectByExample(example);
    }


    public int listCount(Integer userId) {
        AgedmallPromoteWithdrawalRecordExample example = new AgedmallPromoteWithdrawalRecordExample();
        example.or().andUserIdEqualTo(userId);
        Long count = agedmallPromoteWithdrawalRecordMapper.countByExample(example);
        return count.intValue();
    }

}
